#database.py
import sys,shelve
def store_person(db):

    pid = input('enter unique id, ')
    person ={}
    person['name'] = input('enter name, ')
    person['age'] = input('enter age, ')
    person['phone'] = input('enter phone, ')

    db[pid] = person

def lookup(db):
     pid = input('enter unique id, ')
     field = input('enter name or age or phone, ')
     field = field.strip().lower()
     print(field + ':'+ db[pid][field])

def enter_cmd():
    cmd = input('enter cmd, ')
    cmd = cmd.strip().lower()
    return cmd            

def main():
    database = shelve.open('d:\\pydata.dat')
    try:
        while True:
            cmd = enter_cmd()
            if cmd == 's':
                store_person(database)
            elif cmd =='l':
                lookup(database)
            else:
                # print('quit......')
                return
    finally:database.close()

if __name__ == '__main__':
    main()
